package com.dd.ms.consumer.service.internal;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dd.ms.common.pojo.annotation.ServiceDescription;
import com.dd.ms.consumer.converter.DataObjectConverter;
import com.dd.ms.provider.api.DataObjectFeignClient;
import com.dd.ms.provider.pojo.DataObjectBO;
import com.dd.ms.provider.pojo.req.DataObjectPageQueryReq;
import com.dd.ms.provider.pojo.view.DataObjectVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author liuxianmeng
 * @CreateTime 2025/3/12 19:14
 * @Description ConsumerServiceImpl
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class ConsumerServiceImpl {

    @ServiceDescription("dd-ms-provider-Feign(DataObjectDO)客户端")
    private final DataObjectFeignClient dataObjectFeignClient;

    public Page<DataObjectVO> pageVO(DataObjectPageQueryReq req) {
        Page<DataObjectBO> dataObjectBOPage = dataObjectFeignClient.pageFeign(req);
        List<DataObjectVO> dataObjectVOList = dataObjectBOPage.getRecords().stream()
                .map(DataObjectConverter::convert2VO).collect(Collectors.toList());

        Page<DataObjectVO> dataObjectVOPage = new Page<>();
        BeanUtils.copyProperties(dataObjectBOPage, dataObjectVOPage);
        return dataObjectVOPage.setRecords(dataObjectVOList);
    }
}
